﻿using System.IO;
using System.Xml.Serialization;
using Loki.Game;

namespace toNyxPhysRanger
{
    [XmlRoot("FlaskSettings")]
    public class FlaskSettings
    {

        [XmlIgnore] private string _defaultSettingsPath = string.Format(Loki.Utilities.Xml.XmlSettings.SettingsDirectory + "\\toNyxPhysRangerSettings\\{0} - {1}\\",
            LokiPoe.ObjectManager.Me.League, 
            LokiPoe.ObjectManager.Me.Name);

        #region FlaskSettings

        [XmlElement("LifeFlaskThreshold")] public float LifeFlaskThreshold;

        [XmlElement("ManaFlaskThreshold")] public float ManaFlaskThreshold;

        [XmlElement("UseGraniteFlask")] public bool UseGraniteFlask;

        [XmlElement("GraniteFlaskThreshold")] public float GraniteFlaskThreshold;

        [XmlElement("UseJadeFlask")] public bool UseJadeFlask;

        [XmlElement("JadeFlaskThreshold")] public float JadeFlaskThreshold;

        [XmlElement("UseRubyFlask")] public bool UseRubyFlask;

        [XmlElement("RubyFlaskThreshold")] public float RubyFlaskThreshold;

        [XmlElement("UseDiamondFlask")] public bool UseDiamondFlask;

        [XmlElement("DiamondFlaskThreshold")] public float DiamondFlaskThreshold;

        [XmlElement("UseBleedingFlask")] public bool UseBleedingFlask;

        [XmlElement("BleedingFlaskThreshold")] public float BleedingFlaskThreshold;

        [XmlElement("UseShockFlask")] public bool UseShockFlask;

        [XmlElement("ShockFlaskThreshold")] public float ShockFlaskThreshold;

        [XmlElement("UseBurningFlask")] public bool UseBurningFlask;

        [XmlElement("BurningFlaskThreshold")] public float BurningFlaskThreshold;

        [XmlElement("UseFrozenFlask")] public bool UseFrozenFlask;

        [XmlElement("FrozenFlaskThreshold")] public float FrozenFlaskThreshold;

        [XmlElement("UseDivinationFlask")] public bool UseDivinationFlask;

        [XmlElement("DivinationFlaskThreshold")] public float DivinationFlaskThreshold;

        #endregion

        public void SaveFlasksData()
        {
            // Handling Namespaces
            var ns = new XmlSerializerNamespaces();
            ns.Add("", "");

            string path = _defaultSettingsPath + "FlaskSettings.xml";

            if (!Directory.Exists(_defaultSettingsPath))
                Directory.CreateDirectory(_defaultSettingsPath);

            var xs = new XmlSerializer(typeof(FlaskSettings));
            using (var sw = new StreamWriter(path.Replace(@"\\", @"\")))
            {
                xs.Serialize(sw, this, ns);
            }
        }

        public void GetFlasksData()
        {
            string path = _defaultSettingsPath + "FlaskSettings.xml";

            if (!File.Exists(path)) return;

            var xs = new XmlSerializer(typeof(FlaskSettings));
            using (var rd = new StreamReader(path))
            {
                var tempFlaskSettings = (FlaskSettings)xs.Deserialize(rd);

                // HOLY MOLLY DATA !!!
                LifeFlaskThreshold = tempFlaskSettings.LifeFlaskThreshold;
                ManaFlaskThreshold = tempFlaskSettings.ManaFlaskThreshold;
                UseGraniteFlask = tempFlaskSettings.UseGraniteFlask;
                GraniteFlaskThreshold = tempFlaskSettings.GraniteFlaskThreshold;
                UseJadeFlask = tempFlaskSettings.UseJadeFlask;
                JadeFlaskThreshold = tempFlaskSettings.JadeFlaskThreshold;
                UseRubyFlask = tempFlaskSettings.UseRubyFlask;
                RubyFlaskThreshold = tempFlaskSettings.RubyFlaskThreshold;
                UseDiamondFlask = tempFlaskSettings.UseDiamondFlask;
                DiamondFlaskThreshold = tempFlaskSettings.DiamondFlaskThreshold;
                UseBleedingFlask = tempFlaskSettings.UseBleedingFlask;
                BleedingFlaskThreshold = tempFlaskSettings.BleedingFlaskThreshold;
                UseShockFlask = tempFlaskSettings.UseShockFlask;
                ShockFlaskThreshold = tempFlaskSettings.ShockFlaskThreshold;
                UseBurningFlask = tempFlaskSettings.UseBurningFlask;
                BurningFlaskThreshold = tempFlaskSettings.BurningFlaskThreshold;
                UseFrozenFlask = tempFlaskSettings.UseFrozenFlask;
                FrozenFlaskThreshold = tempFlaskSettings.FrozenFlaskThreshold;
                UseDivinationFlask = tempFlaskSettings.UseDivinationFlask;
                DivinationFlaskThreshold = tempFlaskSettings.DivinationFlaskThreshold;
            }
        }

    }
}
